package com.itboye.shop.category.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.itboye.shop.R;
import com.itboye.shop.bean.ZiLeiMuBean;
import com.itboye.shop.util.helper.ImageLoader;
import com.itboye.shop.util.loadutil.Const;

import java.util.List;


/**
 * Created by a on 2016/5/13.
 */
public class MyListViewAdapter2 extends BaseAdapter{
    private  String[][] allData;
    private  Context context;
    private  int selectIndex;
    List<ZiLeiMuBean> leiMuBeanList;
    public MyListViewAdapter2(List<ZiLeiMuBean> allData, Context context, int selectIndex) {
        this.leiMuBeanList=allData;
        this.context=context;
        this.selectIndex=selectIndex;
    }

    @Override
    public int getCount() {
        return leiMuBeanList.get(selectIndex).getChildren().size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if(convertView==null){
            convertView=View.inflate(context, R.layout.item_listview_2,null);
            vh=new ViewHolder();
            vh.tv= (TextView) convertView.findViewById(R.id.textview);
            vh.simpleDraweeView= (SimpleDraweeView) convertView.findViewById(R.id.simpleDraweeView);
            convertView.setTag(vh);
        }else {
            vh= (ViewHolder) convertView.getTag();
        }

        ImageLoader.loadImage(vh.simpleDraweeView, Const.IMAGE_HEAD+leiMuBeanList.get(selectIndex).getChildren().get(position).getImg_id());
        if (leiMuBeanList.get(selectIndex).getChildren().size()>0) {
            vh.tv.setText(leiMuBeanList.get(selectIndex).getChildren().get(position).getName());
        }

        return convertView;
    }

    public void setIndex(int index){
        selectIndex=index;
    }

    class ViewHolder{
        TextView tv;
        SimpleDraweeView simpleDraweeView;
    }
}
